//
//  OAuthRequestParams.m
//  OSChina
//
//  Created by 8b410-2 on 16/12/30.
//  Copyright © 2016年 abb. All rights reserved.
//

#import "OSCOAuthRequestParams.h"
#import "OSCAccountTools.h"

const NSArray *___GrantType;
// 创建初始化函数。等于用宏创建一个getter函数
#define cGrantTypeGet (___GrantType == nil ? ___GrantType = [[NSArray alloc] initWithObjects: \
@"authorization_code",\
@"refresh_token", nil] : ___GrantType)
// 枚举 to 字串
#define cGrantTypeString(type) ([cGrantTypeGet objectAtIndex:type])
// 字串 to 枚举
#define cGrantTypeEnum(string) ([cGrantTypeGet indexOfObject:string])

@implementation OSCOAuthRequestParams
- (instancetype)init {
    if (self = [super init]) {
        _client_id = Client_ID;
        _client_secret = Client_Secret;
        _grant_type = cGrantTypeString(GrantTypeCode);
        _redirect_uri = Redirect_URL;
    }
    return self;
}
- (instancetype)initWithGrantType:(GrantType)grantType {
    if (self = [super init]) {
        _client_id = Client_ID;
        _client_secret = Client_Secret;
        _grant_type = cGrantTypeString(grantType);
        _redirect_uri = Redirect_URL;
        if (grantType == GrantTypeRefreshToken) {
            _refresh_token = [OSCAccountTools shareSession].account.refresh_token;
        }
    }
    return self;
}
@end
